package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Contact;
import com.kaishengit.entity.Contactnote;
import com.kaishengit.entity.Employee;
import com.kaishengit.util.db.DBHelp;
import com.kaishengit.util.db.RowMapper;

public class ContactnoteDao {
	private DBHelp<Contactnote> db = new DBHelp<Contactnote>();
	public class ContactnoteRowMapper implements RowMapper<com.kaishengit.entity.Contactnote>{

		public Contactnote mapRow(ResultSet rs) throws SQLException {
			Contactnote c = new Contactnote();
			c.setId(rs.getString("id"));
			c.setContent(rs.getString("content"));
			c.setCreatetime(rs.getString("createtime"));
			c.setContactid(rs.getString("contactid"));
			c.setEmployeeid(rs.getString("employeeid"));
			return c;
		}
		
	}
	public List<Contactnote> findByContactIdAndEmployeeId(String cid, String eid) {
		String sql = "select id,content,createtime,employeeid,contactid FROM t_contactnote WHERE contactid = ? and employeeid = ? order by createtime desc";
		return db.executeQueryToList(sql, new ContactnoteRowMapper(), cid,eid);
	}
	public void save(Contactnote c) {
		String sql = "insert into t_contactnote (id,content,employeeid,contactid) values(?,?,?,?)";
		db.executeSQL(sql, c.getId(),c.getContent(),c.getEmployeeid(),c.getContactid());
		
	}
	public Contactnote findById(String id) {
		String sql = "select * from t_contactnote where id = ?";
		return db.executeQueryToObject(sql, new ContactnoteRowMapper(), id);
	}
	
	
}
